<?php
namespace app\index\controller;

use think\Controller;
use app\common\model\user\Users;
use app\common\model\user\UserPay;

class Base extends Controller
{
	/**
	 * 用户保存的session
	 * @var unknown
	 */
	protected $user_id;
	
	/**
	 * request
	 * @var unknown
	 */
	protected $reqeust;
	
	protected $redis;
	
	public function _initialize()
	{
// 		session('user_id',1);
		header('Access-Control-Allow-Origin:*');
		$this->reqeust = request();
        $this->user_id = session('user_id');
        //启动redis缓存
        $this->redis = new \Redis();
        $this->redis->connect('127.0.0.1', 6379);
        if(!$this->user_id){
        	echo json_encode([
        			'code' => 4,
        			'msg' => '请先登录'
        	]);exit;
        }
        //判断用户是否被封号
        $user_state = Users::where(['id' => $this->user_id])->value('state');
        if($user_state == 2) {
        	echo json_encode([
        			'code' => 4,
        			'msg' => '该账户已被封号'
        	]);exit;
        }
	}
	
	public function checkReal($user_id)
	{
		//获取用户信息
		$user = Users::get($user_id);
		if(!$user->is_cert){
			echo json_encode([
					'code' => 5,
					'msg' => '请先实名认证'
			]);exit;
		}
		/* $user_pay = UserPay::where(['user_id' => $user_id])->value('id');
		if(!$user_pay) {
			echo json_encode([
					'code' => 6,
					'msg' => '请先添加收款方式'
			]);exit;
		} */
	}
}